<?php include("head.php"); ?>
    <div class="sui-layout">
		  <div class="sidebar">
<?php include("leftmenu.php"); ?>	  	
		  </div>
		  <div class="content">
			<p class="sui-text-xxlarge my-padd">成绩列表</p>
            <!-- 所有课程的列表 -->
            <table class="sui-table table-primary">
                <tr><th>id</th><th>学号</th><th>课程编号</th><th>成绩</th><th>操作</th></tr>
                <?php
                    include("conn.php");
                    //执行sql语句

                    $sql2 = "select count(*) as allnum from `选修`"; //可以显示出总页数

                    $results = mysqli_query($conn, $sql2); //返回从第pageNum页开始的5条记录
                    $pageNum= empty($_GET["pageNum"])?1:$_GET["pageNum"];  //默认从1开始
                    $pagesize = 3; //约定每页显示5条
                        
                    $a = mysqli_fetch_assoc($results);
                    $page = ($pageNum-1)*$pagesize;
                    $cont = $a['allnum'];
                    $end = ceil($cont/$pagesize);
                    // var_dump($a);
                    $sql = "select * from 选修 limit " . $page . "," . $pagesize;
                    $result = mysqli_query($conn, $sql); //返回从第pageNum页开始的5条记录
                    
                    if( mysqli_num_rows($result)>0 ){
                        while ($arr = mysqli_fetch_assoc($result)){
                            echo "<tr>
                                <td>{$arr['id']}</td>
                                <td>{$arr['学号']}</td>
                                <td>{$arr['课程编号']}</td>
                                <td>{$arr['成绩']}</td>
                                <td>
                                    <a class='sui-btn btn-small btn-warning' href='chengji-edit.php?kid={$arr['id']}'>修改</a>
                                    <a class='sui-btn btn-small btn-warning' href='chengji-del.php?kid={$arr['id']}'>删除</a>
                                </td>
                            </tr>";
                        }
                    }else{
                        echo "暂没有记录";
                    }
                ?>
            </table>
            <a href="?pageNum=1">首页</a>
            <a href="?pageNum=<?php echo $pageNum==1?1:($pageNum-1) ?>">上一页</a>
            <a href="?pageNum=<?php echo $pageNum==$end?$end:($pageNum+1) ?>">下一页</a>
            <a href="?pageNum=<?php echo $end ?>">尾页</a>
		  </div>
		</div>		
    </div>
<?php include("foot.php"); ?>